﻿using System;
using System.Diagnostics;

namespace Bettzueche.Dampfross
{
    /// <summary>
    /// Ein <see cref="Hexagon"/> mit <see cref="KachelContent"/>.
    /// </summary>
    [DebuggerDisplay("Kachel({Content})")]
    [Serializable]
    public class Kachel : Hexagon<KachelContent>
    {
        public Kachel() : base() {
            Content = new KachelContent();
        }
    }

    /// <summary>
    /// Der Inhalt einer <see cref="Kachel"/> mit Landschafts-Typ und Flussmarkierungen.
    /// </summary>
    [Serializable]
    public class KachelContent
    {
        /// <summary>
        /// Gibt die Art des Feldes (<see cref="Bettzueche.Dampfross.Kacheltyp">Kacheltyp</see>).
        /// </summary>
        /// <value>
        /// The type.
        /// </value>
        public Kacheltyp Typ { get; private set; }

        /// <summary>
        /// Gibt an, welche Übergänge mit Fluss sind.
        /// </summary>
        /// <value>
        /// The fluss flags.
        /// </value>
        public Rivers FlussFlags { get; private set; }

        /// <summary>
        /// Gets a value indicating whether [Kachel hat fluss].
        /// </summary>
        /// <value>
        ///   <c>true</c> if [hat fluss]; otherwise, <c>false</c>.
        /// </value>
        public bool HatFluss { get { return (FlussFlags != 0); } }

        /// <summary>
        /// Initializes a new instance of the <see cref="KachelContent"/> class.
        /// </summary>
        /// <param name="typ">The typ.</param>
        /// <param name="riverFlags">The river flags, die angeben, an welcher/n Kante(n) ein Flussübergang ist.</param>
        public KachelContent(Kacheltyp typ, Rivers riverFlags) {
            Typ =  typ;
            FlussFlags = riverFlags;
        }

        public KachelContent() {

        }

        /// <summary>
        /// Returns a hash code for this instance.
        /// </summary>
        /// <returns>
        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
        /// </returns>
        public override int GetHashCode() {
            int hash = 13;
            hash = 17 *  hash + (int)Typ;
            hash = ((int)FlussFlags) ^ hash;
            return hash;
        }

        /// <summary>
        /// Determines whether the specified <see cref="System.Object" />, is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
        /// <returns>
        ///   <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj) {
            KachelContent other = obj as KachelContent;
            if (other == null) {
                return false;
            }
            else
                return Equals(other);
        }

        /// <summary>
        /// Equalses the specified other.
        /// </summary>
        /// <param name="other">The other.</param>
        /// <returns></returns>
        public bool Equals(KachelContent other) {
            return (this.Typ == other.Typ) && (this.FlussFlags == other.FlussFlags);
        }

        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public override string ToString() {
            return Typ.ToString() + " " + Convert.ToString((int)FlussFlags, 2);
        }
    }
}
